package com.zzq.guli.service.oss.controller;

import com.zzq.guli.service.base.result.R;
import com.zzq.guli.service.oss.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

@CrossOrigin //接口上
@RestController
@RequestMapping("/file")
public class FileController {


    @Autowired
    FileService fileService;


    //文件上传
    @PostMapping("/upload")
    public R fileUpload(MultipartFile file) throws IOException {
        InputStream fileStream = file.getInputStream();
        String fileName=file.getOriginalFilename();
        String s = fileService.fileUpload(fileStream,fileName);
        System.out.println(s);
        return R.ok().data("url",s);
    }

    //删除文件
    @DeleteMapping("/removeImage")
    public R fileDelete(@RequestBody String filePath){
        Boolean aBoolean = fileService.removeImage(filePath);
        return R.ok().message("照片删除成功");
    }
}
